package com.cps.match.xmlparser;

import com.cps.match.sdo.EnquiryRequest;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.MapperWrapper;

public class EnquiryRequestParser {

	public static XStream configXtreamRequest() {
		XStream stream = new XStream(new DomDriver()) {
			@Override
			protected MapperWrapper wrapMapper(MapperWrapper next) {
				return new UpperCaseMapper(next);
			}
		};
		
		stream.alias("ns2:TerminationInquiryRequest", EnquiryRequest.class);
		stream.omitField(EnquiryRequest.class, "offset");
		stream.omitField(EnquiryRequest.class, "ref");
		stream.registerConverter(new ConvertAcquirerId());

		return stream;
	}

	public static String marshall(EnquiryRequest request) {
		XStream xStream = configXtreamRequest();
		StringBuffer sb = new StringBuffer();
		sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
		sb.append(xStream.toXML(request));
		String ret = sb.toString();
		ret=ret.replaceFirst("TerminationInquiryRequest", "TerminationInquiryRequest xmlns:ns2=\"http://mastercard.com/termination\"");
		return ret;
	}

}
